package com.wzm.ssm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.wzm.ssm.model.User;
import com.wzm.ssm.service.IUserService;

@Controller
@RequestMapping("/user")
public class UserController {
	@Autowired
	private IUserService userService;

	@RequestMapping(value="{id}/show",method=RequestMethod.GET)
	public String show(@PathVariable int id,Model model) throws Exception{
		User user = userService.load(id);
		model.addAttribute("user", user);
		return "user/show";  //-->webapp/WEB-INF/pages/user/show.jsp
	}
	
	@RequestMapping(value="/list",method=RequestMethod.GET)
	public String list(Model model) throws Exception{
		List<User> users=userService.getUsers();
		model.addAttribute("users", users);
		return "user/list";  //-->webapp/WEB-INF/pages/user/list.jsp
	}
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add() throws Exception{
		return "redirect:/user/add";  //-->webapp/WEB-INF/pages/user/add.jsp
	}
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String add(User user) throws Exception{
		int flag=userService.add(user);
		if(flag>0){
			
		}else{
			
			
		}
		return "redirect:/user/add";  //-->webapp/WEB-INF/pages/user/list.jsp
	}
}
